{*****************************************************************************
  Name           : Unit1
  Author         : TAOY
  Copyright      :(c) 2006 TaoYuan
  Description    : TCorePlugin Core Plugin Class
  History        :

  Date         By                   Description
  ----         --                   -----------
  2006-3-27   TAOY         Initial creation of the Unit.
 *****************************************************************************}
unit Unit1;

interface

uses
  Forms,
  Rcl,
  OpenPFI, 
  RDApplication, RDApplicationPlugin, RDServiceApplication;

type
  TCorePlugin = class(TApplicationPlugin, IApplication)
  private
    OldApplication: TApplication;
    procedure Run;
  protected
    procedure Start; override; stdcall;
    procedure Stop; override; stdcall; 
    { IApplicationPlugin }
    function initApplication(config: TExtendedProperties): IApplication; override;
        stdcall;
    { IApplication }
    procedure startApplication(HostApplication: TApplication); stdcall;
    procedure stopApplication; stdcall;
  public
    destructor Destroy; override;
  end;



implementation

uses
  SysUtils;

destructor TCorePlugin.Destroy;
begin
  Application := OldApplication;
  inherited;
end;

{ TCorePlugin }

function TCorePlugin.initApplication(config: TExtendedProperties): IApplication;
begin
  Supports(Self, IApplication, Result);
end;

procedure TCorePlugin.Run;
begin
  repeat
    try
      Application.HandleMessage;
    except
      Application.HandleException(Application);
    end;
  until Application.Terminated;
end;

procedure TCorePlugin.Start;
begin
  inherited;

end;

procedure TCorePlugin.startApplication(HostApplication: TApplication);
begin
  OldApplication := Application;
  Application := HostApplication;

//Create and startup manager.

  Run;
end;

procedure TCorePlugin.Stop;
begin
  inherited;
end;

procedure TCorePlugin.stopApplication;
begin

end;

end.
